package cn.usts.edu.lesson02;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class TcpClientDemo01 {
    public static void main(String[] args) {
        Socket socket=null;
        OutputStream os = null;

        // 1*要知道服务器的地址
        try {
            InetAddress ServerIP = InetAddress.getByName("127.0.0.1");
            int port=9999;
            socket = new Socket(ServerIP, port);//建立一个插座
            os = socket.getOutputStream();
            os.write("第一个tcp聊天室".getBytes());

        } catch (IOException e) {
            e.printStackTrace();
        }


        if (socket!=null){
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (os!=null){
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
